package cn.itsource.basic.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 专门用来给前端返回信息的
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {

    //成功失败大状态
    private Boolean success = true;

    //返回信息
    private String message = "ok";

    //返回数据
    private Object data;

    //状态码
    private String code = PetConstant.SYSTEM_NORMAL; //魔法值

    /**
     * 返回成功,不携带数据给前端
     */
    public static JsonResult creatSuccess(){
        return new JsonResult();
    }

    /**
     * 返回成功,携带数据给前端
     */
    public static JsonResult createSuccess(Object data) {
        return new JsonResult(true, "OK", data, PetConstant.SYSTEM_NORMAL);
    }

    /**
     * 返回错误
     */
    public static JsonResult creatError(String code,String message){
        return new JsonResult(false, message, null, code);
    }

    /**
     * 返回错误,错误码默认系统错误
     */
    public static JsonResult creatError(String message){
        return creatError(PetConstant.SYSTEM_UNUSUAL,message);
    }

}
